package com.qxy.dydemo;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class TVList extends AppCompatActivity {
    RecyclerView mRecyclerView;
    MyAdapter mMyAdapter ;
    List<News> mNewsList = new ArrayList<>();
    List<TVItem> mTVItemList = new ArrayList<>();
    private Button toMovieListButton;
    private Button toShowListButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tvlist);
        toMovieListButton= (Button)findViewById(R.id.button);
        toShowListButton= (Button)findViewById(R.id.button2);


        toMovieListButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(TVList.this,MovieList.class);
                startActivity(intent);
            }
        });

        toShowListButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(TVList.this,ShowList.class);
                startActivity(intent);
            }
        });

        mRecyclerView = findViewById(R.id.recyclerView);
        // 构造一些数据
        for (int i = 0; i < 50; i++) {
            News news = new News();
            news.title = "标题" + i;
            news.content = "内容" + i;
            mNewsList.add(news);
        }

        for (int i = 0; i < 50; i++) {
            TVItem tvItem = new TVItem();
            tvItem.actors = "主演" + i;
            tvItem.director = "导演" + i;
            tvItem.hotness = "热度" + i;
            tvItem.tv_name = "名字" + i;
            mTVItemList.add(tvItem);
        }




        mMyAdapter = new MyAdapter();
        mRecyclerView.setAdapter(mMyAdapter);
        LinearLayoutManager layoutManager = new LinearLayoutManager(TVList.this);
        mRecyclerView.setLayoutManager(layoutManager);



    }






    class MyAdapter extends RecyclerView.Adapter<MyViewHolder> {

        @NonNull
        @Override
        public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = View.inflate(TVList.this, R.layout.tvlist_item, null);
            MyViewHolder myViewHolder = new MyViewHolder(view);
            return myViewHolder;
        }

        @Override
        public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
         /*   News news = mNewsList.get(position);
            holder.mTitleTv.setText(news.title);
            holder.mTitleContent.setText(news.content);*/
            TVItem tvItem = mTVItemList.get(position);
            holder.mDirector.setText(tvItem.director);
            holder.mActor.setText(tvItem.actors);
            holder.mtvName.setText(tvItem.tv_name);
            holder.mHotness.setText(tvItem.hotness);
        }

        @Override
        public int getItemCount() {
            return mTVItemList.size();
        }
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView mDirector;
        TextView mActor;
        TextView mHotness;
        TextView mtvName;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            mtvName = itemView.findViewById(R.id.tv1);
            mActor = itemView.findViewById(R.id.tv2);
            mDirector= itemView.findViewById(R.id.tv3);
            mHotness= itemView.findViewById(R.id.tv4);

        }
    }
}

